class Solution:
    def hIndex(self, citations: list) -> int:
        res, length = 0, 0
        for i in range(1, len(citations) + 1):
            if citations[-i] > res:
                length += 1
                res = min(length, citations[-i])
                if length == citations[-i]:
                    break
        return res


a = Solution()
print(a.hIndex([0, 1, 3, 5, 6]))
